package com.itheima.mapper;

import com.itheima.domain.Trip;
import org.apache.ibatis.annotations.*;
import org.springframework.context.annotation.PropertySource;

import java.util.List;

public interface TripMapper {

    // 查询行程表中所有的数据
    @Select("select id,username,gender,idcard,from_address fromAddress,to_address toAddress,start_time startTime from tb_trip")
    List<Trip> findAll();

    //添加用户过年的行程数据
    @Insert("insert into tb_trip values(null,#{username},#{gender},#{idcard},#{fromAddress},#{toAddress},#{startTime})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void addTrip(Trip trip);

    //根据ID查询用户的行程数据
    @Select("select id,username,gender,idcard,from_address fromAddress,to_address toAddress,start_time startTime  from tb_trip where id = #{id}")
    Trip findById(@Param("id") Long id);

    //根据ID修改用户的行程数据
    @Update("update tb_trip set username =#{username},gender=#{gender},idcard=#{idcard}," +
            "from_address=#{fromAddress},to_address=#{toAddress},start_time = #{startTime} " +
            "where id =#{id}")
    void updateTripById(Trip trip);

    //根据ID删除用户的行程数据
    @Delete("delete from tb_trip where id = #{id}")
    void deleteTripById(@Param("id") Long id);
}
